package com.bestcem.xm.txtanls.enums;

import lombok.Getter;
import lombok.ToString;

import java.util.Objects;

/**
 * 文本分析项目状态枚举
 *
 * @author XiaoYunSong <ys.xiao@idiaoyan.com>
 * @version v1.0
 * @date 2021/5/8
 */
@Getter
@ToString
public enum AnalysisStatusEnum {
    /**
     * 未开始
     */
    INACTIVE("inactive", 0),
    /**
     * 训练中
     */
    ACTIVE("active", 1),
    /**
     * 已失效
     */
    INVALID("invalid", 2),
    /**
     * 已删除
     */
    DELETED("deleted", 3),
    /**
     * 失败
     */
    FAILED("failed", 4),
    /**
     * 已创建
     */
    CREATED("created", 5),
    /**
     * 已完成
     */
    FINISHED("finished", 6);

    private final String name;

    private final int index;

    AnalysisStatusEnum(String name, int index) {
        this.name = name;
        this.index = index;
    }

    /**
     * 项目状态中文（包含训练中（1）、等待中（0和5）、训练完成（6）三种状态）
     *
     * @param status status 值
     * @param trainStatus 训练状态
     * @param trainProgress 训练进度
     * @return 状态翻译中文
     */
    public static String getStatusName(Integer status, Integer trainStatus, Integer trainProgress) {
        String statusName = "训练失败";
        if (Objects.isNull(status)){
            return statusName;
        }
        if (FINISHED.getIndex() == status || INACTIVE.getIndex() == status) {
            return "训练完成";
        }
        if (status == CREATED.getIndex()) {
            if (Objects.isNull(trainStatus)){
                return "等待中";
            }
            if (TrainStatusEnum.UNFINISHED.getIndex() == trainStatus) {
                return "训练中";
            } else if (TrainStatusEnum.FINISHED.getIndex() == trainStatus) {
                return "等待中";
            }
        } else if (ACTIVE.getIndex() == status) {
            return "等待中";
        }
        return statusName;
    }
}
